package com.rran.study.designpattern.behavioral.memento;

/**
 * @author yy
 * @Type Test.java
 * @Desc
 * @date 2020/7/24 12:46
 */
public class Test {

    public static void main(String[] args) {
        Caretaker caretaker = new Caretaker();
        Originator player = new Originator(1,100L);
        System.out.println("开始游戏,游戏进度为第"+player.getGameLevel()+"关，血量为"+player.getBlood());
        player.setBlood(80L);
        player.setGameLevel(2);
        System.out.println("游戏进度为第"+player.getGameLevel()+"关，血量为"+player.getBlood());
        Memento memento = player.create();
        caretaker.addMemento(memento);
        System.out.println("玩家存档中");
        player.setBlood(50L);
        player.setGameLevel(3);
        System.out.println("游戏进度为第"+player.getGameLevel()+"关，血量为"+player.getBlood());
        //这里为了测试就默认玩家选了之前的存档
        Memento memento1 = caretaker.getMemento(memento.getIndex());
        player.load(memento1);
        System.out.println("游戏进度为第"+player.getGameLevel()+"关，血量为"+player.getBlood());
    }
}
